#include "includes2.h"
#include "pocs2.h"
// Forward projection projector.
using namespace std;
void P4fproject(ScanData & s, int j)
{
	int i;
	float correc=0, norm=0,x,sum=0;
	for (i=0;i<s.Nx;i++){
		if (!s.APmask[i][j] && s.CSmask[i][j]) {
			sum = sum + s.dx*s.recon[i][j];
			x = s.xmin + i*s.dx;
			norm = norm + s.dx / sqrt(s.X2- x*x);
		}
	}
	correc = (s.FPdata[j] - sum)/norm;
	
	for (i=0 ; i < s.Nx ; i++){
		x = s.xmin + i*s.dx;
		if (!s.APmask[i][j] && s.CSmask[i][j]){
			s.recon[i][j] = s.recon[i][j] + correc / sqrt(s.X2 - x*x);
		}
	}

}


void P4fproject_perp(ScanData & s, int i)
{
	int j;
	float correc=0, norm=0,y,sum=0;
	for (j=0;j<s.Ny;j++){
		if (!s.APmask_perp[i][j] && s.CSmask[i][j]) {
			sum = sum + s.dy*s.recon[i][j];
			y = s.ymin + j*s.dy;
			norm = norm + s.dy / sqrt(s.X2- y*y);
		}
	}
	correc = (s.FPdata[i] - sum)/norm;
	
	for (j=0 ; j < s.Ny ; j++){
		y = s.ymin + j*s.dy;
		if (!s.APmask_perp[i][j] && s.CSmask[i][j]){
			s.recon[i][j] = s.recon[i][j] + correc / sqrt(s.X2 - y*y);
		}
	}

}
